package mo.org.cm309.shoppingcart.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mo.org.cm309.shoppingcart.entity.User;
import mo.org.cm309.shoppingcart.service.RoleService;
import mo.org.cm309.shoppingcart.service.UserService;
import mo.org.cm309.shoppingcart.utility.CommonUtility;

public class UserRegistrationServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String firstName   = req.getParameter("firstName");
		String lastName    = req.getParameter("lastName");
		String eMail       = req.getParameter("eMail");
		String password    = req.getParameter("password");
		String rePassword  = req.getParameter("rePassword");
		String phoneNumber = req.getParameter("phoneNumber");
		String address     = req.getParameter("address");
		String creditCardNo= req.getParameter("creditCardNo");
		String cardExpiry  = req.getParameter("cardExpiry");
		
		User user = new User();
		user.setFirstname(firstName);
		user.setLastname(lastName);
		user.setEmail(eMail);
		user.setPassword(password);
		user.setPhoneNum(phoneNumber);
		user.setAddress(address);
		user.setCreditCard(creditCardNo);
		user.setCardExpiry(cardExpiry);
		user.setRoleId(RoleService.getrService().getIdByName(CommonUtility.ROLE_ADMIN_NAME));
		UserService uservice = new UserService(); 
		uservice.register(user);
	}
}
